Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the junit test cases for CustomSearchNarrowingInterceptor #70

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

vsinghht
Copy link

Overview

  • Added the tests for buildAuthorizedList for patientclaim and without patientclaim

How it was tested

  • Tested by running the tests locally.

Checklist

  • The title contains a short meaningful summary
  • I have added a link to this PR in the Jira issue
  • I have described how this was tested
  • I have included screen shots for changes that affect the user interface
  • I have updated unit tests
  • I have run unit tests locally
  • I have updated documentation (including README)

Copy link

@hankwallace hankwallace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you review the built-in tests for SearchNarrowingInterceptor?

https://github.com/hapifhir/hapi-fhir/blob/fb3e141c4d7b790b824132b833c4bddc52e03835/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/interceptor/auth/SearchNarrowingInterceptorTest.java#L65

Testing the "rule" is not sufficient. There should be practical tests using resource search, etc.

public void before() throws IOException {
MockitoAnnotations.openMocks(this);
ourReturn = Collections.emptyList();
ourLastHitMethod = null;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would you want to test the "last hit method"?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have followed the upstream repo tests, as when we search for fhirResource( observation or patient ), the variable ourLastHitMethod will return the method name we have hit so it helps to verify right method has been called during execution.

@Override
protected AuthorizedList buildAuthorizedList(RequestDetails theRequestDetails) {
try (MockedStatic<OAuth2Helper> mockedStatic = mockStatic(OAuth2Helper.class)) {
mockedStatic.when(() -> OAuth2Helper.hasToken(any())).thenReturn(true);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mocking, and replacing, the functionality of the OAuth2Helper invalidates the entire test. Tests SHOULD NOT know about the helper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants